# -*- coding: utf-8 -*-            
# @Author : HJH
# @Time : 2024/2/26 15:48
# @Use :
import json
from datetime import datetime
from topsdk.client import TopApiClient, TopException
from topsdk.defaultability.defaultability import Defaultability
from topsdk.defaultability.request.alitrip_policy_domfare_compare_request import *


def send_request(flight_no: str, dep: str, arr: str, cabin: str, depDate, arrDate):
    # create Client
    client = TopApiClient(appkey='25346003', app_sercet='aeda58e87f78ea981a141ac507e5a940',
                          top_gateway_url='http://39.98.61.147/huifei/',
                          verify_ssl=False)
    ability = Defaultability(client=client)

    # 航程信息
    odInfoQueryDTO = AlitripPolicyDomfareCompareOdInfoQueryDTO()
    odInfoQueryDTO.index = 0
    odInfoQueryDTO.dep_airport = dep
    odInfoQueryDTO.arr_airport = arr
    odInfoQueryDTO.dep_start_date = f'{depDate} 00:00:00'
    odInfoQueryDTO.dep_end_date = f'{arrDate} 23:59:59'

    # 查询参数
    compareDomFareRequestDTO = AlitripPolicyDomfareCompareCompareDomFareRequestDTO()
    compareDomFareRequestDTO.trip_type = 0
    compareDomFareRequestDTO.flight_no_str = flight_no
    compareDomFareRequestDTO.support_code_share = 0
    compareDomFareRequestDTO.sale_mode_codes = [0]
    compareDomFareRequestDTO.cabin_code_str = cabin
    compareDomFareRequestDTO.od_infos = [odInfoQueryDTO]
    compareDomFareRequestDTO.agent_id = 5252

    # create request
    request = AlitripPolicyDomfareCompareRequest()
    request.compare_dom_fare_request_d_t_o = compareDomFareRequestDTO
    try:
        response = ability.alitrip_policy_domfare_compare(request,
                                                          '6102a098713e7108013e55b21b78e46c0f649d29cd2fedf4259705970')
        print(json.dumps(response))
        return response
    except TopException as e:
        print(e)
        return None


if __name__ == '__main__':
    send_request('CZ6509', 'SHE', 'PVG', 'T', '2024-03-06', '2024-03-06')
